package de.gameduell.framework.facebook.app {
	import de.gameduell.framework.debug.Debug;
	import de.gameduell.framework.util.FlashVars;

	public class SplittestConfig {
		
		private static var instance:SplittestConfig;
		private var requestLifeSettings:Array;
		private var lifeTimerSettings:Array;
		private var lastUserId:int;
		private var jackpotSettings:Array;

		public static function getInstance():SplittestConfig {
			if(instance == null){
				instance = new SplittestConfig();
			}
			return instance;
		}
		
		public function SplittestConfig(){
			var userId:String = Controller.getInstance().facebookData.userId;
			lastUserId = int(userId.substr(userId.length - 1, 1));
			
			Debug.trace("SplittestConfig::SplittestConfig: user.uid -> " + userId + " lastId: " + lastUserId, Debug.DEBUG);

			/**
			user IDs ending with > Case
			
			0,1 > a) Normal wie jetzt
			2,3 > b) Refill Lives Rate auf 15 Minuten
			4,5>  c) Request Lives Feature ist aktiviert
			6,7 > d) Request Lives Feature ist aktiviert UND die Refill Rate ist auf 15 min
			8,9 > e) Request Lives Feature ist aktiviert UND die Refill Rate ist auf 25 min 
			 
			*/
//			settings per userid			   (0		 1		  2		   3	    4        5        6        7        8        9      )
			requestLifeSettings = new Array(false,	 false,	  false,   false,   false,   false,   false,   false,   false,    false);
			lifeTimerSettings   = new Array(1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000);
			jackpotSettings     = new Array(false,	 false,	  false,    false,	false,    false,    false,    false,    false,   false);
			
			// FIXME workaround for feature-check config - OVERRIDES !!
			// requestLifeEnabled : "true",
			// lifeTimer : "120000",
			// jackpotEnabled : "true",
			
			if(FlashVars.getKeyValue("requestLifeEnabled") != FlashVars.NO_VALUE){
				requestLifeSettings[lastUserId] = FlashVars.getKeyValue("requestLifeEnabled") == "true";
				Debug.trace("SplittestConfig::SplittestConfig: OVERRIDE SPLITTEST-SETTINGS (requestLifeSettings) " + requestLifeSettings[lastUserId], Debug.WARNING);
			}
			
			if(FlashVars.getKeyValue("lifeTimer") != FlashVars.NO_VALUE){
				var rechargeTime:int = int(FlashVars.getKeyValue("lifeTimer")) == 0 ? lifeTimerSettings[lastUserId] : int(FlashVars.getKeyValue("lifeTimer"));
				lifeTimerSettings[lastUserId] = rechargeTime;
				Debug.trace("SplittestConfig::SplittestConfig: OVERRIDE SPLITTEST-SETTINGS (lifeTimerSettings) " + lifeTimerSettings[lastUserId], Debug.WARNING);

			}
			
			if(FlashVars.getKeyValue("jackpotEnabled") != FlashVars.NO_VALUE){
				jackpotSettings[lastUserId] = FlashVars.getKeyValue("jackpotEnabled") == "true";
				Debug.trace("SplittestConfig::SplittestConfig: OVERRIDE SPLITTEST-SETTINGS (jackpotSettings) " + jackpotSettings[lastUserId], Debug.WARNING);
			}
		}
		
		public function get requestLifeEnabled():Boolean {
			return requestLifeSettings[lastUserId];
		}
		
		public function get lifeTimerTick():int {
			return lifeTimerSettings[lastUserId];
		}
		
//		public function get jackpotEnabled():Boolean {
//			Debug.trace("SplittestConfig::get jackpotEnabled: " + Controller.getInstance().gameData.coins, Debug.WARNING);
//			Debug.trace("SplittestConfig::get jackpotEnabled: " + jackpotSettings[lastUserId], Debug.WARNING);
//			return jackpotSettings[lastUserId] && Controller.getInstance().gameData.coins > 150;
//		}
	}
}
